package cn.lysj.framework.customer.repository;

import cn.lysj.framework.base.BaseRepository;
import cn.lysj.framework.customer.domain.CustomerVip;
import cn.lysj.framework.customer.vo.CustomerVipInfoVo;
import cn.lysj.framework.customer.vo.StoreCustomerVipInfoVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author zwj
 * @description VIP用户数据处理层
 * @create 2019-01-15 15:43:50
 **/
public interface CustomerVipRepository extends BaseRepository<CustomerVip> {
    @Query(value = "select new cn.lysj.framework.customer.domain.CustomerVip (a.storeId,a.id) from CustomerVip a,CustomerInfo b where a.customerInfoId = b.id and a.storeId = ?1 and b.birthday between ?2 and ?3 ")
    List<CustomerVip> ableGetBirthdayCouponCustomerVip(String storeId, Date beginTime, Date endTime);

    @Query(value = "select new cn.lysj.framework.customer.vo.CustomerVipInfoVo(c.id,c.name,c.phone,c.birthday,a.id,a.integral,a.birthdayGetCouponRecord,a.newVipGetCouponRecord)from CustomerVip a,Customer b,CustomerInfo c where a.customerInfoId = c.id and b.customerInfoId = c.id and a.storeId = ?1 and b.id = ?2")
    CustomerVipInfoVo judgeCustomerVip(String storeId, String customerId);

    CustomerVip findByStoreIdAndCustomerInfoId(String storeId,String customerInfoId);

    @Query(value = "select new cn.lysj.framework.customer.vo.StoreCustomerVipInfoVo(b.name, b.phone, b.birthday, a.integral) from CustomerVip a,CustomerInfo b where a.customerInfoId = b.id and a.storeId = ?1")
    Page<StoreCustomerVipInfoVo> queryStoreCustomerVipInfo(Pageable pageable, String storeId);


}
